package cn.iocoder.yudao.module.engine.websocket.heart;

import cn.iocoder.yudao.framework.handlermapping.NettyWsChannelContext;
import cn.iocoder.yudao.framework.handlermapping.NettyWsHandlerComponent;
import cn.iocoder.yudao.framework.handlermapping.NettyWsMapping;
import cn.iocoder.yudao.framework.message.ClientRequest;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

/**
 * 心跳请求接口
 *
 * @author: wds_prc
 * @since: 2024/7/13 22:08
 */
@NettyWsHandlerComponent
@Slf4j
public class HeartRequestHandler {

    @NettyWsMapping("/system/heart")
    public void heart(NettyWsChannelContext ctx, ClientRequest request) {
        final Long userId = ctx.getUser().getUserId();
        log.info("收到心跳包, userId = {}", userId);
        final JSONObject data = new JSONObject();
        data.put("serverTime", System.currentTimeMillis());
        ctx.writeAndFlush(data);
    }

}
